﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using G.Navigate;

namespace G.Reader.View.Message
{
    public partial class SearchFriendPage : GBasePage
    {
        public SearchFriendPage()
        {
            InitializeComponent();
            client.SearchUserByKeyCompleted += new EventHandler<UserInfoService.SearchUserByKeyCompletedEventArgs>(client_SearchUserByKeyCompleted);
            client.AddFriendsCompleted += new EventHandler<UserInfoService.AddFriendsCompletedEventArgs>(client_AddFriendsCompleted);
        }

        void client_AddFriendsCompleted(object sender, UserInfoService.AddFriendsCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                if (e.Result.IsOk)
                {
                    this.ShowState("添加成功");
                }
                else
                {
                    this.ShowState(e.Result.Message);
                }
            }
        }

        void client_SearchUserByKeyCompleted(object sender, UserInfoService.SearchUserByKeyCompletedEventArgs e)
        {
            listbox_users.ItemsSource=e.Result;
        }
        UserInfoService.UserInfoServiceClient client = new UserInfoService.UserInfoServiceClient();
        private void txtSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                if (!string.IsNullOrEmpty(txtSearch.Text))
                    client.SearchUserByKeyAsync(txtSearch.Text);
            }
        }

    }
}